var utils = require('../../../utils/util.js');
var c = require('../../../utils/config.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        bill_nav: [
            '收入记录',
            '支出记录'
        ],
        total_name:'总收入',
        select: 0,
        status:1,
        ym:'',
        lists: []
    },

    onShow: function () {
        utils.checkLogin();
        this.getList();
    },
    //下拉刷新
    onPullDownRefresh: function () {
        this.setData({
          lists: [],
          ym:'',
        });
        this.getList();
    },
    //上拉加载
    onReachBottom: function () {
        // this.setData({
        //   lists: [],
        //   ym:'',
        // });
        //this.getList();
    },

    getList:function(){
        var that = this;
        var token = wx.getStorageSync("userinfo").wap_token;
        var data = {
            url:"/yluser/orderjifen/lists",
            token:token,
            ym:this.data.ym,
            status:this.data.status,
        };
        utils.request(data).then(function(res){
            if (res.code == 0) {
                var data = res.data.list
                var total = parseFloat(0);
                data.forEach((item, index) => {
                    total += parseFloat(item.money);
                });
                that.setData({
                    lists:data,
                    ym:res.data.ym,
                    total_money:total.toFixed(2)
                });
                wx.stopPullDownRefresh();
            }
        });
    },
    select_nav: function (e) {
        let k = e.currentTarget.dataset.index;
        // 0 |收入  1 |支出
        var value = 0;
        var total_name='';
        switch(k){
            case 0:
                value = 1;
                total_name = '总收入';
                break;
            case 1:
                value = -1;
                total_name = '总支出';
                break;
            default:
                value = 1;
                total_name = '总收入';
                break;
        }
        this.setData({
            select: k,
            status:value,
            total_name:total_name,
            ym:'',
        })
        this.getList();
    },
    bindDateChange: function (e) {
        this.setData({
            ym: e.detail.value
        })
        this.getList();
    }
})